package com.beidouin.sensortest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.friendlyarm.AndroidSDK.GPIOEnum;
import com.friendlyarm.AndroidSDK.HardwareControler;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    public static final String APPLICATION_BEIDOUIN = "com.beidouin.sensortest";
    public static final String APPLICATION_HUACE = "com.huace.sensortest";
    public static final String APPLICATION_BEIDI = "com.beidi.sensortest";
    ListView function;
    static  String[] function_menu={"  首      页",
            "  LED 模 块",
            "  按 键 模 块",
            "  继  电  器",
            "  LCD  屏",
            "  蜂 鸣 器",
            "  摇      杆",
            "  光强传感器",
            "  声音传感器",
            "  超声波测距模块",
            "  加 速 度 计",
            "  指  南  针",
            "  火焰传感器",
            "  人体传感器",
            "  AD 转换模块 ",
            "  GPIO 通 道",
            "  串 口 通 信",
            "  关 于 我 们"};
    ArrayAdapter<String> functionArray;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

        if (APPLICATION_BEIDOUIN.equals(BuildConfig.APPLICATION_ID)){
            setContentView(R.layout.activity_beidouin);

        }else if (APPLICATION_HUACE.equals(BuildConfig.APPLICATION_ID)){
            setContentView(R.layout.activity_huace);

        }else if (APPLICATION_BEIDI.equals(BuildConfig.APPLICATION_ID)){
            setContentView(R.layout.activity_beidi);

        }
        functionArray=new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,function_menu);
        function= (ListView) findViewById(R.id.function_menu);
        function.setAdapter(functionArray);
        function.setOnItemClickListener(this);


        HardwareControler.exportGPIOPin(73);//使能端口
        HardwareControler.setGPIODirection(73, GPIOEnum.OUT);//设置GPIO为输出模式
        HardwareControler.exportGPIOPin(74);//使能端口
        HardwareControler.setGPIODirection(74, GPIOEnum.OUT);//设置GPIO为输出模式
        HardwareControler.exportGPIOPin(75);//使能端口
        HardwareControler.setGPIODirection(75, GPIOEnum.OUT);//设置GPIO为输出模式
        HardwareControler.exportGPIOPin(76);//使能端口
        HardwareControler.setGPIODirection(76, GPIOEnum.OUT);//设置GPIO为输出模式
        HardwareControler.setGPIOValue(73,GPIOEnum.LOW);
        HardwareControler.setGPIOValue(74,GPIOEnum.LOW);
        HardwareControler.setGPIOValue(75,GPIOEnum.LOW);
        HardwareControler.setGPIOValue(76,GPIOEnum.LOW);

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position)
        {
            case 1:
            {
                Intent ledIntent = new Intent(this,LEDActivity.class);
                startActivity(ledIntent);
            }
            break;
            case 2:
            {
                Intent keyIntent = new Intent(this,KeyActivity.class);
                startActivity(keyIntent);
            }
            break;
            case 3:
            {
                Intent relayIntent = new Intent(this,RelayActivity.class);
                startActivity(relayIntent);
            }
            break;
            case 4:
            {
                Intent lcdIntent = new Intent(this,LCDActivity.class);
                startActivity(lcdIntent);
            }
            break;
            case 5:
            {
                Intent pwmIntent = new Intent(this,PWMActivity.class);
                startActivity(pwmIntent);
            }
            break;
            case 6:
            {
                Intent joystickIntent = new Intent(this,JoystickActivity.class);
                startActivity(joystickIntent);
            }
            break;
            case 7:
            {
                Intent temperatureIntent = new Intent(this,LightActivity.class);
                startActivity(temperatureIntent);
            }
            break;
            case 8:
            {
                Intent soundIntent = new Intent(this,SoundActivity.class);
                startActivity(soundIntent);
            }
            break;
            case 9:
            {
                Intent ultrasonicIntent = new Intent(this,UltrasonicActivity.class);
                startActivity(ultrasonicIntent);
            }
            break;
            case 10:
            {
                Intent accelerometerIntent = new Intent(this,AccelerometerActivity.class);
                startActivity(accelerometerIntent);
            }
            break;
            case 11:
            {
                Intent compassIntent = new Intent(this,CompassActivity.class);
                startActivity(compassIntent);
            }
            break;
            case 12:
            {
                Intent fireIntent = new Intent(this,FireActivity.class);
                startActivity(fireIntent);
            }
            break;
            case 13:
            {
                Intent bodyIntent = new Intent(this,BodyActivity.class);
                startActivity(bodyIntent);
            }
            break;
            case 14:
            {
                Intent adchannelIntent = new Intent(this,AdChannelActivity.class);
                startActivity(adchannelIntent);
            }
            break;
            case 15:
            {
                Intent gpioIntent = new Intent(this,GPIOActivity.class);
                startActivity(gpioIntent);
            }
            break;
            case 16:
            {
                Intent serialIntent = new Intent(this,SerialPortActivity.class);
                startActivity(serialIntent);
            }
            break;
            case 17:
            {
                Intent aboutIntent = new Intent(this,AboutUsActivity.class);
                startActivity(aboutIntent);
            }
            break;
        }
    }
}
